<?php

namespace Reusify\Helper;

class Result
{
    public static function json(int $code, string $msg, $data = null)
    {
        $res = self::format($code, $msg, $data);
        return json_encode($res,JSON_UNESCAPED_UNICODE);
    }

    public static function format(int $code, string $msg, $data = null): array
    {
        return [
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
        ];
    }

    public static function success($data = null, string $msg = 'success', int $code = 1)
    {
        return self::json($code, $msg, $data);
    }

    public static function error(int $code = 0, string $msg = 'error', $data = null)
    {
        return self::json($code, $msg, $data);
    }
}